/*
 * Cac phuong thuc kiem tra thong tin nguoi dung nhap vao co du va dung format hay khong
 */
package GUI;

import static GUI.UIFormat.validStringLengthMin;
import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author Bui Thi Mai
 */
public class UIInfo {
    /**
     * Truyen vao cac control chua cac thong tin bat buoc phai nhap vao
     * Ham tra ve gia tri true neu thong tin yeu cau duoc nhap day du
     * va False neu thieu mot trong cac thong tin yeu cau
     * @param controlValues
     * @return 
     */
    public static Boolean isCompletedInfo(ArrayList<String> controlValues){
        for(String s : controlValues){
            if(!validStringLengthMin(s, MyConst.MinStringLength)){
                return false;
            }
          }
        return true;
    }
    
    /**
     * Truyen vao danh sach cac control chua thong tin can dung format
     * Ham tra ve gia tri True neu khong co thong tin nao sai format
     * tra ve false neu co bat ki thong tin nao sai format
     * @param infos
     * @return 
     */
    public static Formats isValidInfos(HashMap<Formats, String> infos){
        if(infos != null){
            for(Formats format: infos.keySet()){
                switch(format.toString()){
                    case "Name":
                        if(!UIFormat.validName(infos.get(format))){
                            return Formats.Name;
                        }
                        break;
                    case "Email":
                        if(!UIFormat.validMail(infos.get(format))){
                            return Formats.Email;
                        }
                        break;
                    case "PhoneNumber":
                        if(!UIFormat.validPhoneNumber(infos.get(format))){
                            return Formats.PhoneNumber;
                        }
                        break;
                    case "Date":
                        if(!UIFormat.validDate(infos.get(format), MyConst.DateFormat)){
                            return Formats.Date;
                        }
                        break;
                }
            }
        }
        else
        {
            return Formats.None;
        }
        return Formats.None;
    }
}
